package com.anolesoft.yr.mbus.crm.mapper;

import com.anolesoft.yr.mbus.crm.entity.CrmBasePartPriceQueryDO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.LocalDateTimeTypeHandler;

import java.util.List;

/**
 * @author zhj
 * @date 2020/9/14 13:36
 */
@Mapper
public interface CrmBasePartPriceQueryMapper {
    @Select("<script>" +
            "select " +
            "a.objuid," +
            "a.cont_main_uid," +
            "a.pre_order_uid," +
            "a.prod_product_uid," +
            "a.crm_base_uid," +
            "a.part_model_uid," +
            "a.offer_person," +
            "a.offer_time," +
            "a.offer_price," +
            "" +
            "b.crm_code b_crm_code," +
            "b.crm_name b_crm_name," +
            "b.crm_other_name b_crm_other_name," +
            "" +
            "c.is_temp c_is_temp," +
            "c.cont_type_uid c_cont_type_uid," +
            "c.sign_date c_sign_date," +
            "c.sign_address c_sign_address," +
            "c.cont_code c_cont_code," +
            "c.customer_contract_code c_customer_contract_code," +
            "c.payment c_payment," +
            "c.cont_title c_cont_title," +
            "c1.name c1_name," +
            "" +
            "d.quotation_code d_quotation_code," +
            "d.state d_state," +
            "" +
            "e.prod_type_uid e_prod_type_uid," +
            "e.prod_code e_prod_code," +
            "e.prod_name e_prod_name," +
            "e1.type_code e1_type_code," +
            "e1.type_name e1_type_name," +
            "e1.type_nature e1_type_nature, " +
            "" +
            "f.part_code f_part_code ," +
            "f.part_name f_part_name," +
            "f.part_brand f_part_brand," +
            "f.part_model f_part_model," +
            "f.part_specification f_part_specification," +
            "f.part_type_uid f_part_type_uid," +
            "f.quantity f_quantity," +
            "f1.type_code f1_type_code," +
            "f1.type_name f1_type_name " +
            "" +
            "from crm_base_part_price a " +
            "left join crm_base b on a.crm_base_uid = b.objuid " +
            "left join cont_main c on a.cont_main_uid = c.objuid " +
            "left join cont_type c1 on c.cont_type_uid = c1.objuid " +
            "left join pre_order d on a.pre_order_uid = d.objuid " +
            "left join prod_production e on a.prod_product_uid = e.objuid " +
            "left join prod_type e1 on e.prod_type_uid = e1.objuid " +
            "left join part_model f on a.part_model_uid = f.objuid " +
            "left join part_type f1 on f.part_type_uid = f1.objuid " +
            " where a.del_flag = 0 " +
            "<if test =\"o.crmBaseUid !=null and o.crmBaseUid != '' \">" +
            "   and a.crm_base_uid = #{o.crmBaseUid, jdbcType=VARCHAR} " +
            "</if>" +
            "<if test =\"o.offerPerson !=null and o.offerPerson != '' \">" +
            "   and a.offer_person like #{o.offerPerson, jdbcType=VARCHAR} " +
            "</if>" +
            "<if test =\"o.ccontCode !=null and o.ccontCode != '' \">" +
            "   and c.cont_code like #{o.ccontCode, jdbcType=VARCHAR} " +
            "</if>" +
            "<if test =\"o.dquotationCode !=null and o.dquotationCode != '' \">" +
            "   and d.quotation_code like #{o.dquotationCode, jdbcType=VARCHAR} " +
            "</if>" +
            "<if test =\"o.eprodCode !=null and o.eprodCode != '' \">" +
            "   and e.prod_code like #{o.eprodCode, jdbcType=VARCHAR} " +
            "</if>" +
            "<if test =\"o.fpartModel !=null and o.fpartModel != '' \">" +
            "   and f.part_model like #{o.fpartModel, jdbcType=VARCHAR} " +
            "</if>" +
            "</script>")
    @Results(id="",value = {
            @Result(id = true, column = "objuid", property = "objuid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "cont_main_uid", property = "contMainUid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pre_order_uid", property = "preOrderUid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "prod_product_uid", property = "prodProductUid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "crm_base_uid", property = "crmBaseUid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "part_model_uid", property = "partModelUid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "offer_person", property = "offerPerson", jdbcType = JdbcType.VARCHAR),
            @Result(column = "offer_time", property = "offerTime", typeHandler = LocalDateTimeTypeHandler.class),
            @Result(column = "offer_price", property = "offerPrice", jdbcType = JdbcType.DECIMAL),

            @Result(column = "b_crm_code", property = "bcrmCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "b_crm_name", property = "bcrmName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "b_crm_other_name", property = "bcrmOtherName", jdbcType = JdbcType.VARCHAR),

            @Result(column = "c_is_temp", property = "cisTemp", jdbcType = JdbcType.INTEGER),
            @Result(column = "c_cont_type_uid", property = "ccontTypeUid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "c_sign_date", property = "csignDate", typeHandler = LocalDateTimeTypeHandler.class),
            @Result(column = "c_sign_address", property = "csignAddress", jdbcType = JdbcType.VARCHAR),
            @Result(column = "c_cont_code", property = "ccontCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "c_customer_contract_code", property = "ccustomerContractCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "c_payment", property = "cpayment", jdbcType = JdbcType.INTEGER),
            @Result(column = "c_cont_title", property = "ccontTitle", jdbcType = JdbcType.VARCHAR),
            @Result(column = "c1_Name", property = "c1Name", jdbcType = JdbcType.VARCHAR),

            @Result(column = "d_quotation_code", property = "dquotationCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "d_state", property = "dstate", jdbcType = JdbcType.INTEGER),

            @Result(column = "e_prod_type_uid", property = "eprodTypeUid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "e_prod_code", property = "eprodCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "e_prod_name", property = "eprodName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "e1_type_code", property = "e1typeCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "e1_type_name", property = "e1typeName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "e1_type_nature", property = "e1typeNature", jdbcType = JdbcType.VARCHAR),

            @Result(column = "f_part_code", property = "fpartCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "f_part_name", property = "fpartName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "f_part_brand", property = "fpartBrand", jdbcType = JdbcType.VARCHAR),
            @Result(column = "f_part_model", property = "fpartModel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "f_part_specification", property = "fpartSpecification", jdbcType = JdbcType.VARCHAR),
            @Result(column = "f_part_type_uid", property = "fpartTypeUid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "f_quantity", property = "fquantity", jdbcType = JdbcType.INTEGER),
            @Result(column = "f1_type_code", property = "f1typeCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "f1_type_name", property = "f1typeName", jdbcType = JdbcType.VARCHAR),
    })
    List<CrmBasePartPriceQueryDO> selectPageConditionList(@Param("o") CrmBasePartPriceQueryDO crmBasePartPriceQueryDO, Page<CrmBasePartPriceQueryDO> page);
}
